﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
                    xmlns:params="clr-namespace:Elysium.Parameters"
                    xmlns:controls="clr-namespace:Elysium.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Type controls:ProgressRing}" TargetType="{x:Type controls:ProgressRing}">
        <Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource HighlightBrush}"/>
        <Setter Property="BorderThickness" Value="3"/>
        <Setter Property="Foreground" Value="{StaticResource AccentBrush}"/>        
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="MinWidth" Value="8px"/>
        <Setter Property="MinHeight" Value="8px"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ProgressRing}">
                    <Border ClipToBounds="True"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Canvas x:Name="PART_Track"
                                RenderTransformOrigin="0.5,0.5">
                            <Canvas.RenderTransform>
                                <RotateTransform Angle="90"/>
                            </Canvas.RenderTransform>
                            <ed:Arc x:Name="BackgroundArc"
                                    Fill="{TemplateBinding Background}"
                                    Stroke="{TemplateBinding BorderBrush}"
                                    StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                                    StartAngle="0"
                                    EndAngle="360"
                                    Stretch="None"
                                    RenderTransformOrigin="0.5,0.5"
                                    Canvas.Left="0" Canvas.Top="0"
                                    Width="{Binding ElementName=PART_Track, Path=ActualWidth}" Height="{Binding ElementName=PART_Track, Path=ActualHeight}">
                                <ed:Arc.RenderTransform>
                                    <RotateTransform Angle="-90"/>
                                </ed:Arc.RenderTransform>
                            </ed:Arc>
                            <ed:Arc x:Name="PART_Arc"
                                    Stroke="{TemplateBinding Foreground}"
                                    StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                                    StartAngle="0"
                                    EndAngle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Percent, Converter={StaticResource PercentToAngleConverter}}"
                                    Stretch="None"
                                    RenderTransformOrigin="0.5,0.5"
                                    Canvas.Left="0" Canvas.Top="0"
                                    Width="{Binding ElementName=PART_Track, Path=ActualWidth}" Height="{Binding ElementName=PART_Track, Path=ActualHeight}">
                                <ed:Arc.RenderTransform>
                                    <RotateTransform Angle="-90"/>
                                </ed:Arc.RenderTransform>
                            </ed:Arc>
                            <Canvas x:Name="PART_BusyBar"
                                    Canvas.Left="0" Canvas.Top="0"
                                    Visibility="Hidden">
                                <Ellipse Fill="{TemplateBinding Foreground}"
                                         StrokeThickness="0"
                                         Width="{TemplateBinding params:Progress.BusyElementSize}"
                                         Height="{TemplateBinding params:Progress.BusyElementSize}">
                                    <Canvas.Left>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="X">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Left>
                                    <Canvas.Top>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="Y">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Top>
                                </Ellipse>
                                <Ellipse Fill="{TemplateBinding Foreground}"
                                         StrokeThickness="0"
                                         Width="{TemplateBinding params:Progress.BusyElementSize}"
                                         Height="{TemplateBinding params:Progress.BusyElementSize}">
                                    <Canvas.Left>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="X">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Left>
                                    <Canvas.Top>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="Y">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Top>
                                </Ellipse>
                                <Ellipse Fill="{TemplateBinding Foreground}"
                                         StrokeThickness="0"
                                         Width="{TemplateBinding params:Progress.BusyElementSize}"
                                         Height="{TemplateBinding params:Progress.BusyElementSize}">
                                    <Canvas.Left>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="X">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Left>
                                    <Canvas.Top>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="Y">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Top>
                                </Ellipse>
                                <Ellipse Fill="{TemplateBinding Foreground}"
                                         StrokeThickness="0"
                                         Width="{TemplateBinding params:Progress.BusyElementSize}"
                                         Height="{TemplateBinding params:Progress.BusyElementSize}">
                                    <Canvas.Left>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="X">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Left>
                                    <Canvas.Top>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="Y">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Top>
                                </Ellipse>
                                <Ellipse Fill="{TemplateBinding Foreground}"
                                         StrokeThickness="0"
                                         Width="{TemplateBinding params:Progress.BusyElementSize}"
                                         Height="{TemplateBinding params:Progress.BusyElementSize}">
                                    <Canvas.Left>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="X">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Left>
                                    <Canvas.Top>
                                        <MultiBinding Converter="{StaticResource AngleToCoordinateConverter}"
                                                      ConverterParameter="Y">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)" Converter="{StaticResource NumberPositiveToNegativeConverter}"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(controls:ProgressRing.Angle)"/>
                                            <Binding ElementName="PART_Track" Path="ActualWidth"/>
                                            <Binding ElementName="PART_Track" Path="ActualHeight"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(params:Progress.BusyElementSize)"/>
                                        </MultiBinding>
                                    </Canvas.Top>
                                </Ellipse>
                            </Canvas>
                        </Canvas>
                    </Border>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="State" Value="Busy"/>
                                <Condition Property="IsEnabled" Value="True"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="BackgroundArc" Property="Visibility" Value="Hidden"/>
                                <Setter TargetName="PART_Arc" Property="Visibility" Value="Hidden"/>
                                <Setter TargetName="PART_BusyBar" Property="Visibility" Value="Visible"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="State" Value="Indeterminate">
                <Setter Property="BorderBrush" Value="{x:Null}"/>
            </Trigger>
            <Trigger Property="State" Value="Busy">
                <Setter Property="BorderBrush" Value="{x:Null}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    
</ResourceDictionary>